package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketAddress;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AddressService;
import com.cskaoyan.service.AddressServiceImpl;
import com.cskaoyan.util.ResponseUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/address/*")
public class AdminAddressServlet extends WdBaseServlet {

    AddressService addressService = new AddressServiceImpl();

    public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Integer page = Integer.parseInt(request.getParameter("page"));
        Integer limit = Integer.parseInt(request.getParameter("limit"));
        String order = request.getParameter("order");
        String sort = request.getParameter("sort");
        String username = request.getParameter("name");
        Integer id=null;
        if (request.getParameter("userId")==null||request.getParameter("userId").equals("")){
             id=null;
        }else {
             id=Integer.parseInt(request.getParameter("userId"));
        }

        CommonData<MarketAddress> data = addressService.query(page,limit,sort,order,username,id);
        ResponseUtil.responseJson(response, BaseRespVo.ok(data));
    }

}
